﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Aga.GestionDeArchivos.Common
{
    public static class MD5Helper
    {

        /// <summary>
        /// Gets the MD5 hash.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static string GetMD5Hash(string value)
        {
            MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();

            byte[] bs = System.Text.Encoding.UTF8.GetBytes(value);
            bs = x.ComputeHash(bs);

            System.Text.StringBuilder s = new System.Text.StringBuilder();
            
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }

            return s.ToString();
        }
    }
}
